home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-12 | 5.2 KB | 275 lines | [TEXT/CWIE] |
- /*
- File: LThermometerPane.cp
-
- Contains: Thermometer indicator pane for PowerPlant.
- An LProgressIndicator subclass.
-
- Version: 2.0
-
- Author: Chris K. Thomas, ckt@best.com
-
- Copyright: ©1995 Chris K. Thomas. All Rights Reserved.
- */
-
- #include <UMemoryMgr.h>
- #include <UDrawingState.h>
- #include <LStream.h>
-
- #include "LThermometerPane.h"
- #include "WindoidUtil.h"
-
- const short kStripesPatID = 128;
-
- SInt32 LThermometerPane::sInstanceCount = 0;
- PixPatHandle LThermometerPane::sStripesPat = NULL;
-
- //
- // ——• Instances ———————————————————————————————————————————————————————————————————————
- //
-
- LThermometerPane *
- LThermometerPane::CreateThermometerFromStream(LStream *inStream)
- {
- return new LThermometerPane(inStream);
- }
-
- LThermometerPane::LThermometerPane(LStream *inStream)
- :LPane(inStream)
- {
- //
- // setup pattern
- //
- if(sInstanceCount < 1)
- sStripesPat = GetPixPat(kStripesPatID);
-
- sInstanceCount++;
- mRight = 0;
- mOriginOffset = 0;
-
- //
- // setup default values
- //
-
- SInt32 min, max, value;
-
- inStream->ReadData(&value, sizeof(SInt32));
- inStream->ReadData(&min, sizeof(SInt32));
- inStream->ReadData(&max, sizeof(SInt32));
-
- SetMinValue(min);
- SetMaxValue(max);
- SetCurrentValue(value);
- SetTaskType(task_Measured);
- }
-
- LThermometerPane::LThermometerPane(const SPaneInfo &inPaneInfo,
- ETaskType inTaskType,
- SInt32 inMin,
- SInt32 inMax,
- SInt32 inStartMax)
- :LProgressIndicator(inTaskType, inMin, inMax, inStartMax),
- LPane(inPaneInfo)
- {
- //
- // setup pattern
- //
- if(sInstanceCount < 1)
- sStripesPat = GetPixPat(kStripesPatID);
-
- sInstanceCount++;
-
- mRight = 0;
- mOriginOffset = 0;
- //
- // we don't check here if this is NULL because a user may
- // not in fact use the infinite stripe capability
- //
- }
-
- LThermometerPane::~LThermometerPane()
- {
- //
- // get rid of pattern
- //
-
- sInstanceCount--;
-
- if(sInstanceCount < 1)
- {
- if(sStripesPat)
- DisposePixPat(sStripesPat);
-
- sStripesPat = NULL;
- }
- }
-
-
- //
- // ——• Calculations ———————————————————————————————————————————————————————————————————————
- //
-
- //
- // • ValueChanged - we've made progress! Let's
- // update the display to reflect this!
- // from LProgressIndicator
- //
-
- void LThermometerPane::ValueChanged()
- {
- if(FocusDraw())
- {
- Rect r;
- short length;
-
- CalcLocalFrameRect(r);
-
- InsetRect(&r, 1, 1);
-
- length = r.right - r.left;
-
- //
- // recalculate the right side of the “fill” rect
- //
-
- if(GetTaskType() == task_Measured)
- {
- Assert_((mMaxValue - mMinValue) != 0); // debug
- mRight = length * mCurValue / (mMaxValue - mMinValue);
- }
-
- DrawInside();
- }
- }
-
-
-
- //
- // ——• Imaging ———————————————————————————————————————————————————————————————————————
- //
-
- //
- // • DrawSelf - from LPane
- //
- void LThermometerPane::DrawSelf()
- {
- DrawBox();
- DrawInside();
- }
-
-
- //
- // • DrawBox - draw our border
- //
- void LThermometerPane::DrawBox()
- {
- Rect r;
- StColorState currStateSavor;
-
- CalcLocalFrameRect(r);
-
- StColorState::Normalize();
-
- FrameRect(&r);
- }
-
-
- //
- // • DrawInside - draw our inner self
- //
- void LThermometerPane::DrawInside()
- {
- Rect r;
- StColorState currStateSavor;
-
- CalcLocalFrameRect(r);
-
- StColorState::Normalize();
-
- InsetRect(&r, 1, 1);
-
- switch(mTaskType)
- {
- case task_Measured:
- {
- Rect empty, full;
- RGBColor emptyColor, fullColor;
-
- empty = full = r;
- empty.left = mRight + r.left + 1; //mRight starts from port origin
- full.right = mRight + r.left;
-
- GetWctbColor((WindowPeek)GetMacPort(), wTingeLight, &emptyColor);
- GetWctbColor((WindowPeek)GetMacPort(), wTingeDark, &fullColor);
-
- RGBForeColor(&emptyColor);
- PaintRect(&empty);
- RGBForeColor(&fullColor);
- PaintRect(&full);
- } break;
-
- case task_Indeterminate:
- {
- DrawInfiniteStripe(r);
- } break;
- }
- }
-
- //
- // • DrawInfiniteStripes - this pattern is used
- // when there's no end in sight to the task
- // As in the Finder's lengthy Find dialog.
- // (hold down command-shift-F in 7.5 Finder to get
- // to the original Find box to try it.)
- //
-
- void LThermometerPane::DrawInfiniteStripe(Rect &inRect)
- {
- Rect localRect = inRect, patternRect;
-
- ThrowIfNULL_(sStripesPat);
-
- const short kOffsetAmount = 2;
-
- //
- // Munge the pixpatpalette to the user's colors
- // we need to do this each time in case the user switches
- // to the Finder and changes her colors.
- //
- // This probably won’t break under System 8, but we’ll use the Appearance
- // Manager then anyway, won’t we?
- //
-
- // * lock down the stripe pattern within this box
- {
- StHandleLocker sta_lock((Handle)sStripesPat);
- StHandleLocker stb_lock((Handle)(**sStripesPat).patMap);
- StHandleLocker stc_lock((Handle)(**(**sStripesPat).patMap).pmTable);
-
- patternRect = (**(**sStripesPat).patMap).bounds;
-
- GetWctbColor((WindowPeek)GetMacPort(), wTingeLight, &(**(**(**sStripesPat).patMap).pmTable).ctTable[0].rgb);
- GetWctbColor((WindowPeek)GetMacPort(), wTingeDark, &(**(**(**sStripesPat).patMap).pmTable).ctTable[1].rgb);
- }
-
- OffsetRect(&localRect, mOriginOffset, 0);
-
- //
- // offset the origin to move the pattern
- //
-
- SetOrigin(mOriginOffset, 0);
- FillCRect(&localRect, sStripesPat);
-
- mOriginOffset += kOffsetAmount;
-
- //
- // if we’ve set the origin past the width of the pattern,
- // return to 0
- //
- if(mOriginOffset > (patternRect.right - patternRect.left - 2))
- mOriginOffset = 0;
-
- SetOrigin(0, 0);
- }
-
-